package com.most.goods.service.impl;

import com.most.goods.dto.People;
import com.most.goods.service.PeopleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class PeopleServiceImpl implements PeopleService {
    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public People add() {
        People people = new People();
        people.setName("111");
        people.setPhone("222");
        People insert = mongoTemplate.insert(people);
        return insert;
    }
 
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void addError() {
        People people = new People();
        people.setName("111211111111");
        people.setPhone("222311111111");
        mongoTemplate.insert(people);
        int i = 1 / 0;
        System.out.println("i=======" + i);
    }
}